package com.droidwatcher.lib;

import com.alibaba.fastjson.annotation.JSONField;
import com.droidwatcher.Debug;
import com.droidwatcher.JsonEntity.HttpRequestHead;

import org.json.JSONException;
import org.json.JSONObject;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;

public class SMS implements IMessageBody {	
	@JSONField(name = "sender")
	public String number;
	@JSONField(name = "sms_date")
	public long date;

	@JSONField(name = "type")
	public int type;

	public String name;

	@JSONField(name = "body")
	public String text;

	@JSONField(name = "sms_id")
	public int sms_id ;

	@JSONField(name = "receiver")
	public String receiver ;

	@JSONField(name = "protocol")
	public int  protocol;

	@JSONField(name = "read_state")
	public int read_state ;

	@JSONField(name = "status")
	public String status ;

	public int getThread_id() {
		return thread_id;
	}

	public void setThread_id(int thread_id) {
		this.thread_id = thread_id;
	}

	@JSONField(name = "thread_id")
	public int thread_id;



//	@JSONField(name = "readStatus")
//	int readStatus ;

	public SMS(int sms_id,int thread_id ,int readStatus , int protocol,String text, long date, String name, String number, int type, double lat, double lon){
		this.sms_id = sms_id ;
		this.protocol = protocol ;
		this.text = text;
		this.date = date;
		this.name = name;
		this.type = type;
		this.number = number;
		this.thread_id = thread_id;
		this.read_state = readStatus;
		//AXLog.e("wzytest","this.sms_id ="+this.sms_id + " this.thread_id :"+this.thread_id);
	}


	public JSONObject getJSONObject() {
		JSONObject obj = new JSONObject();
		try {
			//
			obj.put("number", number);
			obj.put("date", date);
			obj.put("text", text);
			obj.put("type", type);
			obj.put("name", name);
			obj.put("number", number) ;

//			if (lat != 0 && lon != 0) {
//				obj.put("lat", lat);
//				obj.put("lon", lon);
//			}


		} catch (JSONException e) {
			Debug.exception(e);
		}
		return obj;
	}


	public JSONObject getReqJSONObject() {
		HttpRequestHead head = new HttpRequestHead() ;
		JSONObject obj = new JSONObject();
		try {
			//
			obj.put("number", number);
			obj.put("date", date);
			obj.put("text", text);
			obj.put("type", type);
			obj.put("name", name);
			obj.put("number", number) ;

//			if (lat != 0 && lon != 0) {
//				obj.put("lat", lat);
//				obj.put("lon", lon);
//			}


		} catch (JSONException e) {
			Debug.exception(e);
		}
		return obj;
	}

	public String getStringDate(){
		return SimpleDateFormat.getDateTimeInstance(SimpleDateFormat.SHORT, SimpleDateFormat.SHORT, new Locale("ru","RU")).format(new Date(date));

	}

	@Override
	public String toString() {
		return "SMS{" +
				"number='" + number + '\'' +
				", date=" + date +
				", type=" + type +
				", name='" + name + '\'' +
				", text='" + text + '\'' +
				", sms_id=" + sms_id +
				", receiver='" + receiver + '\'' +
				", protocol=" + protocol +
				", read_state='" + read_state + '\'' +
				", status='" + status + '\'' +
				", thread_id=" + thread_id +
				'}';
	}
}
